﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PDX.Services
{
    public class ServiceEntry<T> where T : class
    {
        List<Func<T>> factories = new List<Func<T>>();

        public void AddFactory(Func<T> factory)
        {
            factories.Add(factory);
        }

        public T Resolve()
        {
            if (factories.Count > 0)
            {
                return factories.First().Invoke();
            }
            return null;
        }

        public IEnumerable<T> ResolveAll()
        {
            foreach (var factory in factories)
            {
                yield return factory.Invoke();
            }
        }
    }
}
